#include <system.h>
#include <eeprom.h>
#include "kegscale_mk2.h"
#include "utils.h"
#include "eeprom_utils.h"

#ifndef EEADRH
    //this processor doesn't support eeadrh but it is needed for compilation
    volatile unsigned char eeadrh;
#endif

unsigned short read_short_eeprom( eepaddr_t addr )
{
	return((eeprom_read(addr+1)<<8)|eeprom_read(addr));
}
unsigned long eeprom_uint24_read( eepaddr_t addr )
{
    uint32_t res;
    uint8_t eep8, eep16, eep24;
    eep8  = eeprom_read(addr++);
    eep16 = eeprom_read(addr++);
    eep24 = eeprom_read(addr);
    ASSIGN_24(res, eep8, eep16, eep24);
    return res;
}

void eeprom_uint24_write( eepaddr_t addr, unsigned long data) {
    eeprom_uint8_write(addr++, data & 0xff);
    eeprom_uint8_write(addr++, (data >> 8) & 0xff);
    eeprom_uint8_write(addr, (data >> 16) & 0xff);
}
